/*

 */
package DataAccessObject;

import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author Bui Van Minh
 */
public class Connection {
    public static java.sql.Connection conn(){
        String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
        String usernameDb = "sa";
        String passwordDb = "123";
        String url = "jdbc:sqlserver://";
        String serverName="localhost";
        String portNumber="1433";
        String instanceName="";
        String databaseName="cayphahe";
        java.sql.Connection conn;
        try {
            Class.forName(driver).newInstance();
             conn = DriverManager.getConnection(url + serverName + ":" + portNumber +";instanceName=" + instanceName +";databaseName="+ databaseName, usernameDb, passwordDb);
            return conn;
        }
        catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException e) {
            System.out.println("Error: " + e.toString());
            return conn=null;
        }
    }
}
